home *** CD-ROM | disk | FTP | other *** search
- #include "BSNG API.h"
- #include "standard utils.h"
- #include "Generate.h"
-
- /* these should be moved into standard utils.h */
- OSErr WriteData(BSNGParamBlockPtr inData, const char* inText, long inLength);
- OSErr WriteCString(BSNGParamBlockPtr inData, const char* inString);
- OSErr WritePString(BSNGParamBlockPtr inData, StringPtr inString);
-
-
- /* NOTE: anything between EXAMPLE BEGIN and EXAMPLE END may be safely deleted.
- The rest of the framework, when left in place, will take care of all the
- annoying details. */
-
-
-
- /*
- * UserCalculate:
- * Calculate the serial number here. If you get here, the input has already
- * been validated with UserValidate.
- */
-
- short UserCalculate(BSNGParamBlockPtr inData)
- {
- StringPtr item1 = inData->itemValue[kItemValue1];
- StringPtr item2 = inData->itemValue[kItemValue2];
- StringPtr item3 = inData->itemValue[kItemValue3];
- StringPtr item4 = inData->itemValue[kItemValue4];
- StringPtr item5 = inData->itemValue[kItemValue5];
- short outIndex = -1;
-
- /* EXAMPLE BEGIN ===== */
-
- /* Calculate the SN. */
- myCopyPStr("\p<result>", item4);
-
- /* Set the index of the result field, or leave it alone if you don't
- want to alter the clipboard. */
- outIndex = kItemValue4;
-
- /* EXAMPLE END ======= */
-
- return outIndex;
- }
-
-
-
- /*
- * UserValidate:
- * Check the entry fields to make sure their data is acceptable to the
- * serial number algorithm. Set (error) to true if there's something
- * wrong with them.
- */
-
- Boolean UserValidate(BSNGParamBlockPtr inData)
- {
- StringPtr item1 = inData->itemValue[kItemValue1];
- StringPtr item2 = inData->itemValue[kItemValue2];
- StringPtr item3 = inData->itemValue[kItemValue3];
- StringPtr item4 = inData->itemValue[kItemValue4];
- StringPtr item5 = inData->itemValue[kItemValue5];
- Boolean error = false;
-
- /* EXAMPLE BEGIN ===== */
-
- /* We do some simple checks here if the edit fields are not empty or not
- longer than 8 characters, additionally we could also check if the values
- are really only numbers, but I skipped that because the input filter for
- the edit fields was set to integer anyway (defined in Constructor) */
-
- if ((item2[0] < 1) || (item2[0] > 8))
- {
- /* Tell BSNG which field had the error in it. */
-
- inData->errorInItem = kEditItem2;
- error = true;
-
- /* Setting errorText to anything other than empty causes an error dialog
- to pop up with the specified error text. Leaving it empty and returning
- and error just makes BSNG beep. */
-
- myAppendPStr(inData->errorText, "\pEditField 2 contains a wrong value");
- }
-
- /* EXAMPLE END ======= */
-
- if (error)
- {
- return (false);
- }
-
- return (true);
- }
-
-
-
- /*
- * UserFillDefaults:
- * Initialize the EditFields with initial default values (optional, they are
- * empty otherwise) if you create a name-based generator please make sure
- * that you copy the name, company and/or numCopies values into the
- * corresponding fields
- */
-
- void UserFillDefaults(BSNGParamBlockPtr inData)
- {
- StringPtr item1 = inData->itemValue[kItemValue1];
- StringPtr item2 = inData->itemValue[kItemValue2];
- StringPtr item3 = inData->itemValue[kItemValue3];
- StringPtr item4 = inData->itemValue[kItemValue4];
- StringPtr item5 = inData->itemValue[kItemValue5];
-
- /* EXAMPLE BEGIN ===== */
-
- /* In this example we fill out the default (preferences) values. You
- can fill the fields out however you like. */
-
- myCopyPStr(inData->name, item1);
- myCopyPStr(inData->company, item2);
- myCopyPStr(inData->numCopies, item3);
- myCopyPStr("\p", item4);
-
- /* EXAMPLE END ======= */
- }
-
-
-
- /*
- * UserWriteListHeader:
- * This comes after the program name. If you want to write something only
- * once rather than (numOfListNumbers) times, do it here.
- */
-
- OSErr UserWriteListHeader(BSNGParamBlockPtr inData)
- {
- StringPtr item1 = inData->itemValue[kItemValue1];
- StringPtr item2 = inData->itemValue[kItemValue2];
- StringPtr item3 = inData->itemValue[kItemValue3];
- StringPtr item4 = inData->itemValue[kItemValue4];
- StringPtr item5 = inData->itemValue[kItemValue5];
-
- /* EXAMPLE BEGIN ===== */
-
- if (WritePString(inData, "\pName: ") != noErr) goto failed;
- if (WritePString(inData, item1) != noErr) goto failed;
- if (WritePString(inData, "\p\rCompany: ") != noErr) goto failed;
- if (WritePString(inData, item2) != noErr) goto failed;
- if (WritePString(inData, "\p\rCopies: ") != noErr) goto failed;
- if (WritePString(inData, item3) != noErr) goto failed;
- if (WriteCString(inData, "\r") != noErr) goto failed;
-
- /* EXAMPLE END ======= */
-
- return noErr;
-
- failed:
- return ioErr;
- }
-
-
-
- /*
- * UserWriteListNumber:
- * This comes after the header created by UserWriteListHeader. The serial
- * number has already been generated and now we just need to write the
- * results to file.
- */
-
- OSErr UserWriteListNumber(BSNGParamBlockPtr inData)
- {
- StringPtr item1 = inData->itemValue[kItemValue1];
- StringPtr item2 = inData->itemValue[kItemValue2];
- StringPtr item3 = inData->itemValue[kItemValue3];
- StringPtr item4 = inData->itemValue[kItemValue4];
- StringPtr item5 = inData->itemValue[kItemValue5];
-
- /* EXAMPLE BEGIN ===== */
-
- if (WritePString(inData, "\pSerial: ") != noErr) goto failed;
- if (WritePString(inData, item4) != noErr) goto failed;
- if (WriteCString(inData, "\r") != noErr) goto failed;
-
- /* EXAMPLE END ======= */
-
- return noErr;
-
- failed:
- return ioErr;
- }
-
-
-
- /*
- * UserRandomize:
- * Do whatever randomization you want to do; shuffle entry fields, etc.
- * Anything that gets randomized should get written by UserWriteListNumber
- * rather than UserWriteListHeader.
- */
-
- void UserRandomize(BSNGParamBlockPtr inData)
- {
- StringPtr item1 = inData->itemValue[kItemValue1];
- StringPtr item2 = inData->itemValue[kItemValue2];
- StringPtr item3 = inData->itemValue[kItemValue3];
- StringPtr item4 = inData->itemValue[kItemValue4];
- StringPtr item5 = inData->itemValue[kItemValue5];
-
- /* EXAMPLE BEGIN ===== */
-
- /* This really needs no example. Mess with the item text if necessary.
- mess with internal global data if necessary. */
-
- /* EXAMPLE END ======= */
- }
-
-
-